package com.ytkj.digitalConstruction.controller.assets;

import javax.validation.Valid;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.ytkj.digitalConstruction.ReturnCode;
import com.ytkj.digitalConstruction.httpbean.assets.reqbean.TestReq;



/** 
* @author  
* @E-mail: 
* @date 创建时间：2017年12月1日 下午2:17:21 
* @version 1.0   
*/
@RestController
@RequestMapping("/Test")
public class TestController {
	
    /**
     * @功能描述
     * @param 通用注解校验 @Valid
     * @return
     * @param testReq
     * @param bindingResult
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ReturnCode add(@RequestBody @Valid TestReq testReq,BindingResult bindingResult) {
        if (bindingResult.hasErrors()){
             bindingResult.getFieldError().getDefaultMessage();
        }
        ReturnCode code = new ReturnCode.Builder().Success(false).Msg("测试异常").build();
        //testService.AddDevice();
        return code;
    }
    
    
    /**
     * @功能描述  如果入参校验过于复杂使用@RequestBody ，校验规则自己写
     * @param
     * @return
     * @param testReq
     * @return
     */
    @PostMapping(value = "/handling")
    public ReturnCode handling(@RequestBody TestReq testReq) {
        return new ReturnCode.Builder().build();
    }
    
    @GetMapping(value = "/getstyle/{id}")
    public ReturnCode getstyle(@PathVariable Long id) {
       ReturnCode code = new ReturnCode.Builder().Success(false).Msg("测试异常").build();
        return code;
    }
}
